from django.db import models

#macierz kar i nagrod
class SimilarityMatrix(models.Model):
	def getMatrixElements(self):
		matrix = MatrixElement.objects.filter(similarity_matrix = self)
		return matrix

	def addMatrixElements(self, m):
		value = MatrixElement(similarity_matrix = self, value = m)
		value.save()
		return value.id

	def getCols(self):
		col = MatrixElement.objects.filter()

	elements = property(getMatrixElements)
		
	def getMatrixElementsDescr(self):
		elements_details = []
		elements = self.getMatrixElements()
		
		for i in elements:
			elements_details.append(i.getDetails())
		return elements_details

 	def modMatrixElement(self, element_id, new_el):
 		matrix = MatrixElement.objects.filter(similarity_matrix = self)
		el = matrix.get(id = element_id)
		el.value = new_el
		el.save();
		return
		
#element macierzy
class MatrixElement(models.Model):
	similarity_matrix = models.ForeignKey(SimilarityMatrix)
	value = models.IntegerField()
	
	def getDetails(self):
		return { "id" : self.id,
			 "value" : self.value }
		
#sekwencja
class Sequence(models.Model):
	name = models.CharField(max_length = 50)
	sequence = models.TextField()
	
	def __unicode__(self):
		return self.name
	
	def getDetails(self):
		return { "id" : self.id,
			 "name" : self.name,
			 "sequence" : self.sequence }
